package com.zbkj.admin.controller.platform;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.CommonBatchRequest;
import com.zbkj.common.response.TraceableGroupDetailResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.request.PageParamRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.zbkj.service.service.TraceableGroupService;

import com.zbkj.common.request.TraceableGroupSaveRequest;
import com.zbkj.common.request.TraceableGroupSearchRequest;
import com.zbkj.common.response.TraceableGroupPageDataResponse;

/**
 * 总平台溯源套餐管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/traceable/group")
@Api(tags = "总平台溯源套餐管理") //配合swagger使用

public class PlatformTraceableGroupController {

    @Autowired
    private TraceableGroupService traceableGroupService;

    /**
     * 分页显示溯源套餐表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-07-08
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<TraceableGroupPageDataResponse>> getList(@Validated TraceableGroupSearchRequest request,
                                                                   @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<TraceableGroupPageDataResponse> traceableGroupCommonPage = CommonPage.restPage(traceableGroupService.getListPlatform(request, pageParamRequest));
        return CommonResult.success(traceableGroupCommonPage);
    }

    /**
     * 新增溯源套餐表
     * @param traceableGroupSaveRequest 新增参数
     * @author dazongzi
     * @since 2025-07-08
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated TraceableGroupSaveRequest traceableGroupSaveRequest) {
        if(traceableGroupService.createPlatform(traceableGroupSaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 删除溯源套餐表
     * @param id Integer
     * @author dazongzi
     * @since 2025-07-08
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
        if(traceableGroupService.removeById(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 批量删除
     * @param request
     * @return
     */
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除溯源套餐")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (traceableGroupService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 修改溯源套餐表
     * @param traceableGroupRequest 修改参数
     * @author dazongzi
     * @since 2025-07-08
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated TraceableGroupSaveRequest traceableGroupRequest) {
        if (traceableGroupService.updatePlatform(traceableGroupRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询溯源套餐表详情
     * @param id Integer
     * @author dazongzi
     * @since 2025-07-08
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<TraceableGroupDetailResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(traceableGroupService.getDetailsPlatform(id));
    }

}



